<template>
	<view>
		
		<u-mask :show="show">
			<view class="warp" :style="'margin-top: '+(screenHeight * 0.5 - 180)+'px'">
				<view class="rect" @tap.stop>
					<view class="rect-top">
						<image
							src="https://image01.homedo.com/Files/Images/cms/www/20221219/5395959348777181515_pic1.png"
							mode="" style="width: 540rpx;height: 176rpx;"></image>
						<view class="undata-text">
							<text class="text-top1">发现新版本 V{{regenerativeNum}}</text>
							<text class="text-top2">尊敬的用户您好，本次更新为您带来以下内容：</text>
						</view>
					</view>
					<view class="rect-content">
						<view style="margin: 27rpx 40rpx 0rpx;">
							<view class="text-content1">
								<text>{{updateContent}}</text>
							</view>
						</view>
					</view>
					<view class="rect-bottoms">
						<view @click="upData">
							<text class="text-bottom3">立即更新</text>
						</view>
					</view>
				</view>
			</view>
		</u-mask>
		
	</view>
</template>

<script>
import { BASE_URL } from '@/config'
	import {regeneratives} from '@/common/api/public.js'
	import viewMixin from "@/common/mixin/viewMixin.js";
	export default {
		mixins: [viewMixin],
		name: "undata-module",
		data() {
			return {
				show: false,
				regenerativeNum: "", //新版本
				updateContent: "", //更新描述
				updateType: "", //是否全局
				wgtUrl: "", //热更地址
				pUrl: "",
				constraint: false,
				baseurl:BASE_URL
			}
		},
		created() {
			// this.getViews()
			this.versionNumber()
		},
		methods: {
			//取消
			cancel() {
				this.show = false
			},
			async versionNumber() {
				var deviceInfo = uni.getSystemInfoSync()
				var version = deviceInfo.appVersion || '';
				// var version ='1.0.0';
				console.log(version,'version')
				const response = await regeneratives()
				const data = response.data
				// const data = {
				// 	"apktype": "pda",
				// 	"filename": "__UNI__455AF00.wgt",
				// 	"filerealpath": "/opt/aipu/files/uploadfile/a120faf6609042d880bca599f03ab2a8.wgt",
				// 	"fileurl": "/uploadfile/a120faf6609042d880bca599f03ab2a8.wgt",
				// 	"version": "1.0.4",
				// 	"versiondesc": "1.更新了在线升级的功能，强大的不得了"
				// }
				console.log(data.version,'data.version')
				
			
				
				if (data.version != version) {
					// console.log("最新版本和本地版本不同")
						this.show = true
						this.regenerativeNum = data.version
						this.updateContent = data.versiondesc
						// this.wgtUrl = this.baseurl + '/aipu' +  data.fileurl
						this.wgtUrl = 'http://172.16.197.56:10000/aipu' +  data.fileurl
				} else {
					this.show = false;
				}

			},
			upData() {
				this.show = false
				// uni.showLoading({
				// 	title: '加载中'
				// });
				// 	this.upDataload()
				// setTimeout(function() {
				// 	uni.hideLoading();
				// }, 1000);
				// },
				// upDataload() {
				//1.调用接口判断是否需要更新，及是否全部更新，还是热更新
				//#ifdef APP-PLUS  
				// var server = this.gengUrl; //检查更新地址
				
					console.log("热更新", this.wgtUrl)
					uni.downloadFile({
						url: this.wgtUrl,
						success: (downloadResult) => {
							console.log("下载返回", downloadResult)
							if (downloadResult.statusCode === 200) {
								plus.runtime.install(downloadResult.tempFilePath, {
										force: true //是否校验版本 true不校验
									},
									function() {
										console.log(
											'install success...'
										);
										plus.runtime.restart(); //热更新要重新启动才能生效
									},
									function(e) {
										console.log('install fail...', e);
									});
							}
						}
					});
			
				//#endif 
				setTimeout(function() {
					uni.hideLoading();
				}, 2000);
			}
		}
	}
</script>

<style scoped>
	.warp {
		display: flex;
		align-items: center;
		justify-content: center;
		/* height: 100%; */
	}

	.rect {
		width: 540rpx;
		border-radius: 16rpx;
		background-color: #fff;
		display: flex;
		justify-content: space-between;
		align-items: center;
		flex-direction: column;
	}

	.rect-top {
		width: 540rpx;
		height: 176rpx;
		position: relative;
	}

	.undata-text {
		position: absolute;
		top: 33rpx;
		left: 32rpx;
	}

	.text-top1 {
		height: 45rpx;
		font-size: 32rpx;
		font-family: PingFangSC-Semibold, PingFang SC;
		font-weight: 600;
		color: #FFFFFF;
		line-height: 45rpx;
	}

	.text-top2 {
		width: 278rpx;
		font-size: 24rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
		line-height: 36rpx;
		margin: 8rpx 0rpx 0rpx 1rpx;
	}

	.rect-content {
		height: 185rpx;
	}

	.text-content1 {
		width: 460rpx;
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #1E1F22;
		line-height: 51rpx;
		height: 200rpx;
		overflow-y: auto;
	}

	.rect-btn {
		width: 330rpx;
		height: 94rpx;
		padding: 0 105rpx 0;
		border-top: 1rpx solid #EEEEEE;
		display: flex;
		justify-content: space-between;
		align-items: center;
		flex-direction: row;
	}

	.rect-bottoms {
		width: 360rpx;
		height: 94rpx;
		padding: 0 105rpx 0;
		border-top: 1rpx solid #EEEEEE;
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: row;
		margin-top: 50rpx;
	}

	.zhan {
		height: 94rpx;
		width: 1rpx;
		background-color: #EEEEEE;
	}

	.text-bottom1 {
		font-size: 32rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #4B4D55;
		line-height: 44rpx;
	}

	.text-bottom2 {
		font-size: 32rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #0090FF;
		line-height: 44rpx;
	}

	.text-bottom3 {
		font-size: 32rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #0090FF;
		line-height: 44rpx;
	}
</style>